package com.example.neusoft.yuejian_tea;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

public class WelcomeActivity extends AppCompatActivity {

    private TextView tvsec,tvgo;
    private int count=3;
    private Animation animation;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            tvsec.setText(count+"");
            count--;
            animation.reset();
            tvsec.startAnimation(animation);

            handler.sendEmptyMessageDelayed(0,1000);
            if(count==-1) {
                Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
                startActivity(intent);

                finish();
            }
            super.handleMessage(msg);
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        //去掉标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_welcome);
        animation = AnimationUtils.loadAnimation(this, R.anim.animation_text);

        handler.sendEmptyMessageDelayed(0,1000);

        tvsec=findViewById(R.id.textView);
        tvgo=findViewById(R.id.textView2);
        tvgo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        });


    }
}
